<?php

/**
 * Created by PhpStorm.
 * User: d7
 * Date: 2016/1/5
 * Time: 14:13
 */
class Activity extends MY_Pc_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->assign('recommend',$this->config->item('content'));
    }

    function detail($activity_id){
        $condition = array('is_del'=>0);
        if($activity_id<0){
            $this->show_message('id错误',404,site_url());
        }
        $this->load->model('activities/Activities_model');
        $condition['id'] = $activity_id;
        $activity = $this->Activities_model->getOne($condition);
        $this->load->model('Comment_model');
        $join_condition = array(array('table_name'=>'users','condition'=>'users.id=activity_comment.user_id','field'=>'id as uid,username'));
        $option = array('limit'=>array(0,5),'order'=>array('activity_comment.id desc'));
        $comments = $this->Comment_model->join_table_fetch_array(array('activity_id'=>$activity_id,'is_del'=>1),'*',$option,$join_condition);
        $this->assign('comments',$comments);
        $this->assign('activity',$activity);
        $this->display();
    }

    function gets(){
        $page = $this->input->get('page');
        $page = $page > 0? $page: 1;
        $is_del = $this->input->get('is_del')>0?1:0;
        $is_sold = $this->input->get('is_sold')>0?1:0;
        $start = $this->input->get('started')>0?1:0;
        $condition = array(
            'is_del'=>$is_del,
            'is_sold'=>$is_sold
        );
        if($start>0){
            $condition['start_time>']=date('Y-m-d H:i:s',time()+3600*24);
        }

        $base_url = url_query($condition,'/activity/gets/');

        $pagination = $this->Activities_model->pagination($base_url, $page, $condition, 'id desc');
        $this->session->set_userdata(
            'back_list_page',
            $this->get_self_url()
        );
        var_dump($pagination);
        $this->assign('pagination', $pagination);
        $this->display();
    }
}